package com.logic.usersinfo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.beans.UserInfoBean;
import com.factory.db.DBFactory;

public class GetUserSelfInfo {

	public List<UserInfoBean> getUserSelfInfoList( String userid ){

		Connection conn = null;

		PreparedStatement pst = null;

		ResultSet rs = null;
		
		System.out.println("[LoginAction]getlist");
		List<UserInfoBean> mList = new ArrayList<UserInfoBean>();
		
		String sql= "SELECT account_use_type, account_type, userid, telphonenum,end_time,  belongwho, add_time, used_flag FROM db.jiankong_account_table WHERE userid= ?";

		conn = DBFactory.getDBConnectionInstance( DBFactory.TYPE_MYSQL ).getDBConnection();

		try {
			pst = conn.prepareStatement(sql);

			pst.setString(1, userid );

			rs = pst.executeQuery();

			while( rs.next() ){
				UserInfoBean bean = new UserInfoBean();

				bean.setAccount_type(rs.getString( "account_type" ));
				bean.setAccount_user_type( rs.getString( "account_use_type" ));
				bean.setAdd_time( rs.getString( "add_time" ));
				bean.setEnd_time( rs.getString( "end_time" ));
				bean.setBelongwho(rs.getString( "belongwho" ) );
				bean.setUsed_flag( rs.getString( "used_flag" ) );

				bean.setTelephone( rs.getString( "telphonenum") );

				bean.setUserid( userid );

				mList.add(bean);

			}
		} catch (SQLException e) {


			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{

			if( rs != null ){

				try {
					rs.close();

					rs = null;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

			if( pst != null ){

				try {
					pst.close();

					pst = null;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

		}

		return mList;

	}
}
